package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBC_connection_Demo1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        /**
         * jdbc快速入门
         */
        //1.注册驱动,使用的是反射触发类和静态代码块注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接

        String url="jdbc:mysql://127.0.0.1:3306/学生库";
        String username="root";
        String password="mysql";

        Connection connection = DriverManager.getConnection(url, username, password);

        //3.定义sql语句
        String sql="INSERT student VALUE('006','李林','男')";

        //4.获取sql的执行对象, statement()
        Statement statement = connection.createStatement();
        //5.执行sql语句
        int i = statement.executeUpdate(sql);
        //6.关流(释放资源)
        statement.close();
        connection.close();
    }
}
